package cn.ekuma.data.ui.android;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import cn.ekuma.android.ui.tree.TreeCallBack;
import cn.ekuma.android.ui.tree.TreeElement;
import cn.ekuma.android.ui.tree.TreeView;
import cn.ekuma.data.dao.bean.I_Category;
import cn.ekuma.data.dao.bean.I_ViewBean;

public class BaseBeanCategorySelecter<T extends I_Category> extends LinearLayout implements TreeCallBack{
	
	TreeView treeview; 
	
	OnBaseBeanSelectedListener l;
	
	AbstractBaseBeanTreeAdapter adapter;

	
	public BaseBeanCategorySelecter(Context context) {
		super(context);
		treeview=new TreeView(context); 
		this.addView(treeview);

	}
	
	public BaseBeanCategorySelecter(Context context, AttributeSet attrs) {
		super(context, attrs);
		treeview=new TreeView(context); 
		this.addView(treeview);
	}
 
	
    public void setAbstractBaseBeanTreeAdapter(AbstractBaseBeanTreeAdapter adapter) {
    	this.adapter=adapter;
    	treeview.setTreeAdapter(adapter);
    	adapter.setCallBack(this);
    }
    
    
    public void setOnBaseBeanSelectedListener(OnBaseBeanSelectedListener l){
    	this.l=l;
    }
    
    public void removeOnBaseBeanSelectedListener(){
    	this.l=null;
    }

	public TreeView getListview() {
		return treeview;
	}

	
	public void elementSelected(TreeElement element) {
		if(l!=null)
			l.baseBeanSelected((I_ViewBean)element.getTag(),element.childCount() );
	}

	
	public Boolean equalByTag(Object tag0, Object tag1) {
		return ((I_Category)tag0).getID().equals(((I_Category)tag1).getID());
	}
    
}